/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package action.Management;

import Database.ContractDAO;
import Models.Contract;
import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author trang_000
 */
@Namespace("/Contract")
public class CreateContractAction extends ActionSupport implements ModelDriven<Contract>{
    private int profileID;
    private Contract contract = new Contract();
    private ContractDAO contractDAO = new ContractDAO();

    public int getProfileID() {
        return profileID;
    }

    public void setProfileID(int profileID) {
        this.profileID = profileID;
    }

    public Contract getContract() {
        return contract;
    }

    public void setContract(Contract contract) {
        this.contract = contract;
    }
    @Override
    @Action(value = "refuser", results = {
        @Result(name = "success", location = "/Management/ManageHome.jsp")})
    public String execute() throws Exception {
        //profile = profileDAO.getProfileByProfileID(profileID);
        
        
        return SUCCESS;
    }    

    @Action(value = "verifier", results = {
        @Result(name = "success", location = "/Management/ManageHome.jsp"),
        @Result(name = "error", location = "/Management/ManageHome.jsp")})
    public String Verifier() throws Exception {
        //profile = profileDAO.getProfileByProfileID(profileID);
        System.out.println("Verifier");
        System.out.println(profileID);
        System.out.println(profileID + " " + contract.getDateBegin().toString());
        System.out.println(profileID + " " + contract.getDateEnd().toString());
        if(contractDAO.insertContract(contract, profileID)){
            return SUCCESS;
        }
        else
        {
            addActionError("Somethings errors. Please try again!");
            return ERROR;
        }
    } 
    
    @Override
    public Contract getModel() {
        return contract; //To change body of generated methods, choose Tools | Templates.
    }
}
